package LeetCode.leetcode98;

import java.util.ArrayList;
import java.util.List;

public class Review1 {
    public boolean isValidBST(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        return test(root,list);
    }
    public static boolean test(TreeNode root, ArrayList<Integer> list){
        if (root == null) return true;
        if (!test(root.left,list)) return false;
        if (list.size() > 0 && root.val <= list.get(list.size()- 1)) return false;
        list.add(root.val);
        return test(root.right,list);
    }
}
